/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package components;
/**
 *
 * @author icdev
 */
import PCR.MainFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class BandMenu extends JPopupMenu {

    MainFrame frm = (MainFrame) java.awt.Window.getWindows()[0];

    public BandMenu() {
        super();
        addMenuItems();
    }

    private void addMenuItems() {
        MenuAction mAction = new MenuAction();
        CheckMenuAction cmAction = new CheckMenuAction();

        JMenuItem deleteItem = new JMenuItem("Delete");
        JCheckBoxMenuItem moveItem = new JCheckBoxMenuItem("Lock");
        JMenuItem resetItem = new JMenuItem("Reset");

        deleteItem.addActionListener(mAction);
        moveItem.addActionListener(cmAction);
        resetItem.addActionListener(mAction);

        if (currentBand != null) {
            moveItem.setSelected(!currentBand.isMovable());
        }

        this.add(deleteItem);
        this.add(moveItem);
        this.add(resetItem);


    }

    class CheckMenuAction implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBoxMenuItem curMenu = (JCheckBoxMenuItem) e.getSource();
            if (curMenu.getText().equals("Lock")) {
                if (curMenu.isSelected()) {
                    currentBand.setMovable(false);
                    currentBand.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                } else {

                    currentBand.setMovable(true);
                    currentBand.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                }
            }
        }
    }

    class MenuAction implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            JMenuItem curMenu = (JMenuItem) e.getSource();
            if (curMenu.getText().equals("Delete")) {
                currentBand.getParent().remove(currentBand);
                frm.repaint();
            }
        }
    }
    BandShape currentBand;

    public void setCurrentBand(BandShape com) {
        currentBand = com;
    }

    public Component getCurrentBand() {
        return currentBand;
    }
}
